using pub.CmdUI.Cmd;
using pub.CmdUI.UI.Control;

namespace todo.Cmd.View
{
    public class ThemeCmd : DefaultCmd, IItemsCmdState
    {
        int? IItemsCmdState.SelectedIndex
        {
            get
            {
                var themeName = App.Settings.ThemeName;
                for (var n = 1; n < Consts.ThemeNames.Length; n++)
                {
                    if (themeName == Consts.ThemeNames[n])
                    {
                        return n;
                    }
                }
                return 0;
            }
        }

        public override void Execute(IControlUI controlUi)
        {
            var itemsControUI = controlUi as IItemsControlUI;
            var index = itemsControUI.SelectedItemIndex ?? 0;
            var themeName = Consts.ThemeNames[index];

            TodoApi.Instance.SetTheme(themeName);

            App.Settings.ThemeName = themeName;
            App.MainForm.UpdateRibbonTheme();
        }
    }
}